package cn.szzsi.business.controller.admin;

import cn.szzsi.common.util.CommonUtil;
import cn.szzsi.common.util.StringUtils;
import cn.szzsi.model.CompanyInfo;
import cn.szzsi.model.Member;
import cn.szzsi.model.MemberRank;
import cn.szzsi.model.SiteConfig;
import com.jfinal.aop.Before;
import com.jfinal.kit.Ret;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.ehcache.CacheName;
import com.jfinal.plugin.ehcache.EvictInterceptor;
import org.apache.commons.codec.digest.DigestUtils;

import java.util.Date;

/**
 *
 *
 */
public class SiteConfigController extends BaseAdminController<SiteConfig> {
    private String shopId;

    public void add(){
        shopId=getAttr("shopId");
        Member member = getLoginMember();
        SiteConfig siteConfig= SiteConfig.getByShopId(shopId);
        CompanyInfo ci=CompanyInfo.dao.getByShopId(shopId);
        setAttr("loginMember", member);
        setAttr("siteConfig",siteConfig);
        setAttr("shopId",shopId);
        setAttr("ci",ci);
        render(CommonUtil.TEMPLATE_PATH+"/business/siteconfig/siteconfig_add.html");
    }

    public void view(){
        shopId=getAttr("shopId");
        SiteConfig siteConfig= SiteConfig.getByShopId(shopId);
        CompanyInfo ci=CompanyInfo.dao.getByShopId(shopId);
        Member member = getLoginMember();
        setAttr("loginMember", member);
        setAttr("siteConfig",siteConfig);
        setAttr("ci",ci);
        render(CommonUtil.TEMPLATE_PATH+"/business/siteconfig/siteconfig_view.html");
    }




    @Before(EvictInterceptor.class)
    @CacheName("SiteConfig")
    public void update(){
        shopId=getAttr("shopId");
        CompanyInfo ci=CompanyInfo.dao.getByShopId(shopId);

        //商户配置相关(companyInfo)
        String brandLogo=getPara("brandLogo");
        String sms_signature=getPara("sms_signature");
        ci.setBrandLogo(brandLogo);
        ci.setSmsSignature(sms_signature);
        ci.update();
        renderJson(Ret.ok("info","修改成功!").set("url","view"));

    }


}

















